﻿@model Xms.Web.Customize.Models.SolutionModel
    <div id="entityCreateSection" class="entityCreateSection">
        <div class="entityCreateSection-close">x</div>
        <iframe width="100%" src="" id="entityCreateIframe" class="ifrmae-list" name="entityCreateIframe" frameborder="0" scrolling="auto" height="114" style="height:100%;"></iframe>
    </div>
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            <a data-toggle="collapse"
                href="#collapseTwo">
                <strong>@app.PrivilegeTree?.LastOrDefault().DisplayName</strong>
            </a>
        </h3>
    </div>
       
    <div id="collapseTwo" class="panel-collapse collapse in">
        <div class="panel-body">
            <div class="" id="gridview">
                <div class="mb-2 toolbar">
                    <form action="/@app.OrganizationUniqueName/customize/@app.ControllerName/@app.ActionName" method="get" id="searchForm" role="form">
                        @Html.ValidationSummary()
                        <div class="row">
                            <div class="col-sm-8">
                                <div class="btn-group btn-group-sm">
                                    
                                    <a class="btn btn-info btn-xs" href="@("/"+app.OrganizationUniqueName)/customize@(Url.Action("createsolution"))"><span class="glyphicon glyphicon-plus-sign"></span> @app.T["add"]</a>
                                    <a class="btn btn-info btn-xs" href="#" data-toggle="modal" data-target="#importModal"><span class="glyphicon glyphicon-import"></span> @app.T["import"]</a>
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="input-group input-group-sm">
                                    @Html.TextBoxFor(x => x.Name, new { @class = "form-control", @placeholder = @app.T["entity_name"] })
                                    <span class="input-group-btn">
                                        <button type="submit" class="btn btn-info btn-block grid-searcher"><span class="glyphicon glyphicon-search"></span> @app.T["search"]</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="table-datagrid-view">
                    <div class="datagrid-view"></div>
                </div>
            </div>
        </div>
    </div>
        

</div>
<!-- （Modal） -->
<div class="modal fade" id="importModal" tabindex="-1" role="dialog"
     aria-labelledby="importModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">
                    @app.T["times_sign"]
                </button>
                <h4 class="modal-title" id="importModalLabel">
                    @app.T["import_solution"]
                </h4>
            </div>
            <div class="modal-body">
                <form id="importForm" action="@("/"+app.OrganizationUniqueName)/customize/solution/importsolution" method="post" enctype="multipart/form-data">
                    <div class="form-group">
                        <label for="col-sm-2 control-label">@app.T["file"]</label>
                        <div class="col-sm-10">
                            <input id="solutionfile" name="file" type="file" class="form-control input-sm" />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">
                    <span class="glyphicon glyphicon-remove"></span> @app.T["cancel"]
                </button>
                <button type="button" class="btn btn-primary" onclick="importSolution()">
                    <span class="glyphicon glyphicon-ok"></span> @app.T["confirm"]
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

@section Header {
    <link href="~/content/customize/css/common.css?v=@app.PlatformSettings.VersionNumber" rel="stylesheet">
    <link href="~/content/js/jquery-ui-1.10.3/themes/base/jquery.ui.all.css?v=@app.PlatformSettings.VersionNumber" rel="stylesheet">
    <link href="~/content/js/grid/pqgrid.dev.css?v=@app.PlatformSettings.VersionNumber" rel="stylesheet">
    <link id="themeLink" href="~/content/css/theme/@(app.Theme).css" rel="stylesheet" />
}
@section Scripts {
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.button.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.mouse.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.autocomplete.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.draggable.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.resizable.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.tooltip.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="~/content/js/fetch.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="~/content/js/common/filters.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/grid/pqgrid.dev.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/grid/localize/pq-localize-zh.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/cdatagrid.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery.bootpag.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery.form.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script>
        var pageUrl = '';
         $(function () {

            var theaders = {
                'name': '名称',
                'version':'版本',
                'createby': '创建者',
                'promulgator': '发布者',
                'createdon': '创建时间',
                'operation':'@app.T["operation"]'
            }
            //列数据配置数据
            var columnConfigs = [
            //从新配置复选框列的渲染方式，
                {
                    title: "", dataIndx: "recordid", maxWidth: 48, minWidth: 48, align: "center", resizable: false,
                    type: 'checkBoxSelection', cls: 'ui-state-default', sortable: false, editable: false,
                    render: function (ui) {
                      //  console.log(ui)
                        return '<input type="checkbox" value="' + ui.rowData.solutionid + '" name="recordid" class="">'
                    },
                    cb: { all: true, header: true }
                },
                {
                    title: "", dataIndx: "hidden", maxWidth: 30, minWidth: 30, align: "center", resizable: false,
                     cls: 'ui-state-default', sortable: false, editable: false,
                    hidden:true,
                    render: function (ui) {
                        //  console.log(ui)
                        return '<input type="hidden" value="' + ui.rowData.solutionid + '" name="componenttypename" class="">'
                    },
                    cb: { all: true, header: true }
                },
                { "dataIndx": "name", "title": theaders.name, editable: false, "dataType": "string", "width": 150, "isprimaryfield": false, "attributetypename": "string" },
                 { "dataIndx": "version", "title": theaders.version, editable: false, "dataType": "string", "width": 150, "isprimaryfield": false, "attributetypename": "string" },
                { "dataIndx": "createby", "title": theaders.createby, "dataType": "string", editable: false, "width": 150, "isprimaryfield": false, "attributetypename": "lookup" },


                { "dataIndx": "promulgator", "title": theaders.promulgator, editable: false, "dataType": "string", "width": 100, "isprimaryfield": false, "attributetypename": "lookup"},
                 { "dataIndx": "createdon", "title": theaders.createdon, editable: false, "dataType": "string", "width": 150, "isprimaryfield": false, "attributetypename": "string" },
                {
                    title: "操作", editable: false, minWidth: 220,width:220, notHeaderFilter: true, editable: false, sortable: false, render: function (ui) {
                        var datas = ui.rowData;
                        var dataIndx = ui.dataIndx;
                        var column = ui.column;
                        var recordid = datas[dataIndx];
                        var html = ''
                        html= '<a class="btn btn-info btn-xs" href="@("/"+app.OrganizationUniqueName)/customize/solution/exportsolution?id='+datas.solutionid+'"><span class="glyphicon glyphicon-export"></span> @app.T["export"]</a>'+
                                ' <a class="btn btn-default btn-xs" href="javascript:;" onclick="openRightSrc(\''+datas.solutionid+'\');"><span class="glyphicon glyphicon-edit"></span> 编辑</a>'
                            ;
                        if (!datas.isdefault) {
                                   html+= ' <a class="btn btn-warning btn-xs" href="javascript:Xms.Web.Del(\''+datas.solutionid+'\',\'/customize/solution/deletesolution\',false,rebind,null,\'确定删除？请提前备份数据\',true)"><span class="glyphicon glyphicon-trash"></span> 删除</a>'
                                }

                        return html
                    }
                }
             ];
             $('body').toggleIframe({offsetH:-100});
           var url = ORG_SERVERURL + '/customize/@app.ControllerName/@app.ActionName?LoadData=true&';
            var $form = $('#searchForm');
            var roles_filters = new XmsFilter();
            var datagridconfig = {
                scrollModel: { autoFit: true },
                baseUrl: url,
                rowDblClick: function (event, ui) {
                    var solutionid = ui.rowData.solutionid;
                    var url = ORG_SERVERURL + '/customize/solution/editsolution?id='+solutionid
                    $('body').toggleIframe('changeSrc',url);
                },
                columnConfigs: columnConfigs,//字段配置信息
                context: $('#gridview'),//底部操作按钮方法触发
                filters: roles_filters,//post提交时过滤条件
                searchForm: $form//GET提交时查询的数据
            };
            $('.datagrid-view').xmsDataTable(datagridconfig);

           Xms.Web.Event.localStorageEvent.on('list_solution_rebind', function () {
                setTimeout(function () {
                    location.reload();
                },100)
            });


              $(".entityCreateSection-close").click(function () {
                closeRecordIframe();
              });
             if (transitionEnd) {
                $("#entityCreateSection").bind(transitionEnd, function (e) {
                    if ($("body").hasClass("rightIframe-open")) {
                        $("#entityCreateSection").removeClass("end");
                    } else {
                        $("#entityCreateIframe").attr("src", '');
                        $("#entityCreateSection").addClass("end");
                    }
                });
            }
         });

        function openRightSrc(solutionid) {
             var url = ORG_SERVERURL + '/customize/solution/editsolution?id='+solutionid
                    $('body').toggleIframe('changeSrc',url);
        }
        //$(function () {
        //    pageUrl = $("#datatable").attr('data-pageurl');
        //    $('#searchForm').ajaxSearch('#gridview', ajaxgrid_reset);
        //    $("#datatable").ajaxTable();
        //    ajaxgrid_reset();
        //    $(".modal").draggable({
        //        handle: ".modal-header",
        //        cursor: 'move',
        //        refreshPositions: false
        //    });
        //    Xms.Web.Event.localStorageEvent.on('list_solution_rebind', function () {
        //        setTimeout(function () {
        //            location.reload();
        //        },100)
        //    });
        //});
        function ajaxgrid_reset() {
            pag_init();
            Xms.Web.DataTable($("#datatable"));
        }
        function pag_init() {
            $('#page-selection').bootpag({
                total: $('#page-selection').attr('data-total')
                , maxVisible: 10
                , page: $('#page-selection').attr('data-page')
                , leaps: false
                , prev: '&lsaquo;'
                , next: '&rsaquo;'
                , firstLastUse: true
                , first: '&laquo;'
                , last: '&raquo;'
            }).on("page", function (event, /* page number here */ num) {
                event.preventDefault();
                pageUrl = $("#datatable").attr('data-pageurl');
                var url = $.setUrlParam(pageUrl, 'page', num);
                $("#gridview").ajaxLoad(url, "#gridview", function (response) {
                    ajaxgrid_reset();
                });
                return false;
            });
        }
         function rebind() {
            //$('#searchForm').submit();
             $('.datagrid-view').cDatagrid('refreshDataAndView')
        }
        function importSolution() {
            $('#importForm').ajaxSubmit(function (response) {
                console.log(response);
                if (response.IsSuccess) {
                    $('#importModal').modal('hide');
                }
                Xms.Web.Alert(response.IsSuccess, response.Content);
                rebind();
            });
        }
    </script>
}